//
//  BaseComponent.h
//  Auction
//
//  Created by Gary on 15/9/13.
//  Copyright (c) 2015年 Lebo. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "NetworkFailView.h"

#ifndef HandleNetworkError
#define HandleNetworkError                                                  \
if (ENetworkManager == ModuleID(notifyID)) {                                \
return;                                                                     \
}                                                                           \
                                                                            \
NSDictionary *requestInfo =                                                 \
[(NSDictionary*)inParam objectForKey:kNetworkRequestInfo];                  \
if (![self isSender:requestInfo]) {                                         \
    return;                                                                 \
}                                                                           \
                                                                            \
if ([_baseComponent networkRequestFailNotify:notifyID inParam:inParam]) {   \
[_baseComponent hideMask];                                                  \
return;                                                                     \
}
#endif

#ifndef EditingInputViewAssignment
#define EditingInputViewAssignment                                      \
- (void)textFieldDidBeginEditing:(UITextField *)textField {             \
_baseComponent.editingTextInputView = textField;                        \
}                                                                       \
                                                                        \
- (BOOL)textFieldShouldReturn:(UITextField *)textField {                \
[textField resignFirstResponder];                                       \
return  YES;                                                            \
}                                                                       \
                                                                        \
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView {             \
_baseComponent.editingTextInputView = textView;                         \
return YES;                                                             \
}
#endif

@class UIViewController;
@protocol NetworkFailDelegate;

@interface BaseComponent : NSObject

@property (nonatomic, weak) UIViewController<NetworkFailDelegate> *decorator;
@property (nonatomic, assign) BOOL                isOrigin;
@property (nonatomic, assign) CGRect              originPortraitFrame;
@property (nonatomic, retain) UIView              *editingTextInputView;
//@property (nonatomic, assign) BOOL                networkRequestFailedProcess;
@property (nonatomic, assign) NSInteger           sendingRequest;//正在发送的请求标识，用于因网络断连等物理原因导致请求失败后，重试哪条请求的判断依据

#pragma mark - Mask and Progress

- (void)showProgressHUD;
- (void)hideProgressHUD;
- (void)showMask;
- (void)hideMask;

#pragma mark - Network Fail

- (NetworkFailView*)networkFailView;
- (void)registerNetworkRequestsFailed:(NSArray *)arr;
- (BOOL)networkRequestFailNotify:(NSUInteger)notifyID inParam:(id)inParam;
- (void)handleNetworkRequestFailed:(NSError*)error;

#pragma mark - Keyboard

- (void)activeKeyboard;
- (void)inactiveKeyboard;
- (void)hideKeyboard;
- (void)keyboardWillChangeFrame:(NSNotification *)notification;
- (void)riseWindowHeight;
- (void)keyboardWillShow:(NSNotification *)notification;
- (void)keyboardWillHide:(NSNotification *)notification;

@end
